<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup">
  <lv-form-item *ngIf="tapeCopy && restoreType === RestoreType.CommonRestore">
    <lv-form-label>{{
      'protection_tape_all_restore_label' | i18n
    }}</lv-form-label>
    <lv-form-control>
      <lv-switch
        formControlName="isDirectRecovery"
      ></lv-switch>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'protection_restore_to_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-radio-group formControlName="restoreLocation">
        <lv-group [lvGutter]="'24px'">
          <lv-radio
            [lvValue]="restoreLocationType.ORIGIN"
            [lvDisabled]="disableOriginLocation"
            [lv-tooltip]="
              disableOriginLocation && !isVolume
                ? ('protection_cloud_origin_restore_disabled_label' | i18n)
                : ''
            "
          >
            {{ 'common_restore_to_origin_location_label' | i18n }}
          </lv-radio>
          <lv-radio [lvValue]="restoreLocationType.NEW">
            {{ 'common_restore_to_new_location_label' | i18n }}
          </lv-radio>
        </lv-group>
      </lv-radio-group>
    </lv-form-control>
  </lv-form-item>
  <ng-container
    *ngIf="formGroup.value.restoreLocation === restoreLocationType.ORIGIN"
  >
    <lv-form-item>
      <lv-form-label>
        {{ 'common_location_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <input lv-input type="text" formControlName="originLocation" />
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container
    *ngIf="formGroup.value.restoreLocation === restoreLocationType.NEW"
  >
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'common_target_host_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-select
          lvShowFilter
          lvFilterKey="label"
          lvFilterMode="contains"
          formControlName="host"
          [lvOptions]="hostOptions"
          lvValueKey="value"
        >
        </lv-select>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container *ngIf="osType === dataMap.Fileset_Template_Os_Type.linux.value && isOsBackup && false">
    <lv-form-item>
      <lv-form-label>
        {{ 'explore_fileset_os_restore_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-switch formControlName="is_OS_restore"></lv-switch>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item *ngIf="formGroup.get('is_OS_restore').value">
      <lv-form-label>
        {{ 'explore_volume_reboot_system_after_restore_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-switch formControlName="reboot_system_after_restore"></lv-switch>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container
    *ngIf="formGroup.value.restoreLocation === restoreLocationType.NEW && !formGroup.get('is_OS_restore').value"
  >
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'common_destination_path_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-tree-select
          formControlName="metadataPath"
          [lvTreeData]="metadataPathData"
          lvTreeSelectionMode="single"
          (lvExpandedChange)="expandedChange($event)"
          [lvTreeNodeTemplate]="nodeTpl"
          lvVirtualScroll
          lvTreeShowLine
          lvShowFilter
          lvFilterKey="label"
          lvFilterMode="contains"
        ></lv-tree-select>
        <ng-template #nodeTpl let-item>
          <div style="width: 380px;" lv-overflow>
            <span *ngIf="!item.isMoreBtn">
              {{ item.label }}
            </span>
          </div>
          <span
            class="aui-link"
            *ngIf="item.isMoreBtn"
            (click)="getHostResource(item.parent, item.startPage)"
            >{{ item.label }}</span
          >
        </ng-template>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container *ngIf="isIncremental">
    <lv-form-item>
      <lv-form-label>
        {{ 'protection_incremental_restore_label' | i18n }}
        <i
          class="configform-constraint"
          lv-icon="aui-icon-help"
          lvTooltipTheme="light"
          lv-tooltip="{{
            'protection_fileset_incremental_restore_tips_label' | i18n
          }}"
          lvColorState="true"
        >
        </i>
      </lv-form-label>
      <lv-form-control>
        <lv-switch formControlName="incrementalRestore"> </lv-switch>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <lv-form-item>
    <lv-form-label>{{
      'protection_over_write_rule_label' | i18n
    }}</lv-form-label>
    <lv-form-control>
      <lv-radio-group formControlName="overwriteType">
        <lv-group [lvGutter]="'20px'" lvDirection="vertical" class="mgt-8">
          <lv-radio [lvValue]="fileReplaceStrategy.Overwriting"
            >{{ 'protection_overwrite_label' | i18n }}
          </lv-radio>
          <lv-radio [lvValue]="fileReplaceStrategy.Skip">{{
            'protection_skip_label' | i18n
          }}</lv-radio>
          <lv-radio [lvValue]="fileReplaceStrategy.Replace">
            {{ 'protection_restore_replace_older_label' | i18n }}</lv-radio
          >
        </lv-group>
      </lv-radio-group>
    </lv-form-control>
  </lv-form-item>
  <div class="advanced-container">
    <lv-collapse [lvType]="'simple'">
      <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="false">
        <lv-form-item>
          <lv-form-label
            >{{ 'protection_channel_number_label' | i18n }}
            <i
              lv-icon="aui-icon-help"
              lv-tooltip="{{ 'protection_fileset_channels_tips_label' | i18n }}"
              lvTooltipTheme="light"
              class="configform-constraint"
              lvColorState="true"
            ></i>
          </lv-form-label>
          <lv-form-control [lvErrorTip]="channelsErrorTip">
            <input
              lv-input
              type="text"
              formControlName="channels"
              placeholder="1-40"
            />
          </lv-form-control>
        </lv-form-item>
        <lv-form-item>
          <lv-form-label>
            {{ 'protection_restore_pre_script_label' | i18n }}
          </lv-form-label>
          <lv-form-control [lvErrorTip]="scriptErrorTip">
            <input
              formControlName="preScript"
              [placeholder]="scriptPlaceholder"
              lv-input
            />
          </lv-form-control>
        </lv-form-item>
        <lv-form-item>
          <lv-form-label>
            {{ 'protection_restore_post_script_label' | i18n }}
          </lv-form-label>
          <lv-form-control [lvErrorTip]="scriptErrorTip">
            <input
              formControlName="postScript"
              [placeholder]="scriptPlaceholder"
              lv-input
            />
          </lv-form-control>
        </lv-form-item>
        <lv-form-item>
          <lv-form-label>
            {{ 'protection_restore_fail_script_label' | i18n }}
          </lv-form-label>
          <lv-form-control [lvErrorTip]="scriptErrorTip">
            <input
              formControlName="executeScript"
              [placeholder]="scriptPlaceholder"
              lv-input
            />
          </lv-form-control>
        </lv-form-item>
      </lv-collapse-panel>
    </lv-collapse>
  </div>
</lv-form>

<ng-template #titleTpl>
  <lv-group lvGutter="8px">
    <span class="custom-collapse-title-text">{{
      'common_advanced_label' | i18n
    }}</span>
    <i
      lv-icon="aui-icon-help"
      lvTooltipTheme="light"
      [lv-tooltip]="scriptTips"
      lvColorState="true"
    >
    </i>
  </lv-group>
</ng-template>
